package net.apexes.codegen.core;

import com.querydsl.codegen.Property;
import com.querydsl.sql.ColumnMetadata;

import java.util.Comparator;

/**
 * @author hedyn
 */
public class ColumnIndexComparator implements Comparator<Property>  {

    @Override
    public int compare(Property o1, Property o2) {
        return Integer.compare(index(o1), index(o2));
    }

    private static int index(Property property) {
        ColumnMetadata metadata = (ColumnMetadata) property.getData().get("COLUMN");
        return metadata.getIndex();
    }

}
